package com.budayi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Mono;

/**
 * @author LIBOFEI
 * @ClassName GatewayApplication
 * @description 网关启动服务
 * @date 2021/4/20 16:19
 * @Version 1.0
 **/
@EnableDiscoveryClient
@SpringBootApplication
public class GatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }


    /** *
     * 限流策略，根据ip限流
     * @author LIBOFEI
     * @date 17:18 2021/4/25
     * @return org.springframework.cloud.gateway.filter.ratelimit.KeyResolver
     * @Version  1.0
    **/
    @Bean
    public KeyResolver hostAddrKeyResolver() {
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
    }




}
